package com.sqx.modules.goodsMessage.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.goodsMessage.entity.GoodsMessage;
import com.sqx.modules.goodsMessage.service.GoodsMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品留言-用户端
 * @author wuChang
 * @since 2024-06-03
 */
@RestController
@Api(value = "商品留言-用户端", tags = {"商品留言-用户端"})
@RequestMapping("/app/goodsMessage/")
public class AppGoodsMessageController {

    @Autowired
    private GoodsMessageService goodsMessageService;

    /**
     * 新增或修改商品留言
     *@param goodsMessage 商品留言
     */
    @Login
    @ApiOperation("新增或修改商品留言")
    @PostMapping(value = "saveGoodsMessage")
    public Result saveGoodsMessage(@ApiParam(value = "用户id")@RequestAttribute Long userId,
                                   @ApiParam("商品留言实体")@RequestBody GoodsMessage goodsMessage) {
        goodsMessage.setUserId(userId);
        return goodsMessageService.saveGoodsMessage(goodsMessage);
    }

    /**
     * 获取商品留言列表
     * @param goodsMessage 商品留言
     */
    @ApiOperation("获取商品留言列表")
    @GetMapping(value = "getGoodsMessageList")
    public Result getGoodsMessageList(@ApiParam(value = "页码")Integer page,
                                      @ApiParam(value = "条数")Integer limit,
                                      @ApiParam("商品留言实体")GoodsMessage goodsMessage) {
        goodsMessage.setIsDelete(0);
        return Result.success().put("data", goodsMessageService.getAppGoodsMessageList(page, limit, goodsMessage));
    }

    /**
     * 删除商品留言
     *@param messageId 商品留言id
     */
    @Login
    @ApiOperation("删除商品留言")
    @PostMapping(value = "deleteGoodsMessageById")
    public Result deleteGoodsMessageById(@ApiParam(value = "用户id")@RequestAttribute Long userId,
                                         @ApiParam(value = "商品留言id")Long messageId) {
        return goodsMessageService.deleteGoodsMessageById(userId,messageId) ;
    }

    @Login
    @ApiOperation("回复商品留言")
    @PostMapping(value = "replyGoodsMessage")
    public Result replyGoodsMessage(@ApiParam(value = "用户id")@RequestAttribute Long userId,
                                    @ApiParam("商品留言实体") GoodsMessage goodsMessage) {
        goodsMessage.setUserId(userId);
        return goodsMessageService.replyGoodsMessage(goodsMessage);
    }
}